package com.fuelwallet.wizard;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.fuelwallet.R;

public class SetupAccountActivity extends Activity {
	
	public static final String CAR_NAME = "car_name";
	
	public static final int DIALOG_EXIT = 10;
	
	private EditText txtName;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setup_account);
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
		
		txtName = (EditText) findViewById(R.id.nickname);
		View nextbtn = this.findViewById(R.id.btn_next_account);		
		nextbtn.setOnClickListener(mClickListener);
	}
	
	// next buttons listener
	private Button.OnClickListener mClickListener = new Button.OnClickListener() {
		public void onClick(View v) {
			String carName = txtName.getText().toString();			
						
			if(carName.length() == 0){
				Toast.makeText(SetupAccountActivity.this, "Please enter your car name! ", Toast.LENGTH_SHORT).show();
				return;
			} else{
				if(carName.length() > 10)
					carName = carName.substring(0, 10);
				
				Intent intent = new Intent(SetupAccountActivity.this, SetupFueltypeActivity.class);
				intent.putExtra(CAR_NAME, carName);
				SetupAccountActivity.this.startActivity(intent);
				SetupAccountActivity.this.finish();
			}
		}
	};
	
	protected Dialog onCreateDialog(int id){
		switch(id){
		case DIALOG_EXIT:
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setMessage("Are you sure you want to exit?")
			       .setCancelable(false)
			       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
			           public void onClick(DialogInterface dialog, int id) {
			                SetupAccountActivity.this.finish();
			                android.os.Process.killProcess(android.os.Process.myPid());
			           }
			       })
			       .setNegativeButton("No", new DialogInterface.OnClickListener() {
			           public void onClick(DialogInterface dialog, int id) {
			                dialog.cancel();
			           }
			       });
			AlertDialog alert = builder.create();
			return alert;
		default:
			return null;
		}
	}
	
	// disable BACK key
	public void onBackPressed(){
		showDialog(DIALOG_EXIT);		
	}
}